package com.xmg.day05;

import com.google.common.primitives.Chars;
import com.google.common.primitives.Ints;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @Author: mazhongqing
 * @Date: 2020/10/23 14:12
 */
public class ReverseDemo1 {
    public static void main(String[] args) {
        String str = "abcdefghijklmn";
        System.out.println(rolate(str,4));
    }

    public static String rolate(String str,int leftSize){
        if(leftSize<=0||leftSize>=str.length()){
            return str;
        }
        return process(str.toCharArray(),0,leftSize-1,str.length()-1);
    }

    public static String process(char[] str,int L,int M,int R){
        reverse(str,L,M);
        reverse(str,M+1,R);
        reverse(str,L,R);
        return String.valueOf(str);
    }

    public static void reverse(char[] str,int L,int R){
        while(L<R) {
            char temp = str[L];
            str[L++] = str[R];
            str[R--] = temp;
        }
    }
}
